package com.lzxuni.modules.informationpublish;


import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lzxuni.modules.common.controller.BaseController;

import com.lzxuni.modules.common.entity.FileEntity;
import com.lzxuni.modules.common.entity.PageData;
import com.lzxuni.modules.common.entity.PageParameter;
import com.lzxuni.modules.common.service.FileEntityService;
import com.lzxuni.modules.informationpublish.entity.InformationPublishPressRelease;
import com.lzxuni.modules.informationpublish.service.InformationPublishPressReleaseService;
import com.lzxuni.modules.productdisplay.entity.ProductDisplay;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.LinkedList;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author fcd
 * @since 2019-06-25
 */
@RestController
@RequestMapping("/PressReleasebaoguangtai")
public class PressReleasebaoguangtaiController extends BaseController {
    @Autowired
    private InformationPublishPressReleaseService informationPublishPressReleaseService;
    @Autowired
    private FileEntityService fileEntityService;
//    @RequestMapping("/Index")
//    public ModelAndView list() throws Exception {
//        ModelAndView mv = new ModelAndView("news");
//////        List list=informationPublishPressReleaseService.queryAll();
//////        mv.addObject("data",list);
//        //新闻中心
//        List<InformationPublishPressRelease> newsList = informationPublishPressReleaseService.list(new QueryWrapper<InformationPublishPressRelease>().ne("news_type","曝光台").orderByDesc("create_time").last("limit 6"));
//        List list1 = null;
//        for(int i=0;i<newsList.size();i++){
//            FileEntity fileEntity = new FileEntity();
//            String id = newsList.get(i).getNewsId();
//            fileEntity.setYwId(id);
//            fileEntity.setYwType("demopic");
//            list1 = fileEntityService.queryListByFileEntity(fileEntity);
//            newsList.get(i).setFileEntities(list1);
//        }
//        mv.addObject("newsList", newsList);
//        return mv;
//    }
//
//    @RequestMapping("/queryid")
//    public ModelAndView queryid(String id){
////       String id = request.getParameter("id");
//        ModelAndView mv = new ModelAndView("news_xx");
//       List list=informationPublishPressReleaseService.queryId(id);
//        mv.addObject("data",list);
//        return mv;
//    }

    //新闻公告
    @RequestMapping(value = "/NewExposureStage/{newsType}", method = RequestMethod.GET)
    public ModelAndView newexposureStage(@PathVariable String newsType) throws Exception {
        ModelAndView mv = new ModelAndView("/news");
        int count = informationPublishPressReleaseService.count(new QueryWrapper<InformationPublishPressRelease>().eq("news_type", newsType));
        mv.addObject("count", count);
        mv.addObject("newsType", newsType);
        return mv;
    }

    //新闻公告详细页
    @RequestMapping(value = "/NewExposureStage_details/{newsId}", method = RequestMethod.GET)
    public ModelAndView newexposureStagedetails(@PathVariable String newsId) throws Exception {
        ModelAndView mv = new ModelAndView("/news_xx");
        List<InformationPublishPressRelease> newsList = informationPublishPressReleaseService.list(new QueryWrapper<InformationPublishPressRelease>().eq("news_id", newsId));
        List list1 = null;
        for (int i = 0; i < newsList.size(); i++) {
            FileEntity fileEntity = new FileEntity();
            String id = newsList.get(i).getNewsId();
            fileEntity.setYwId(id);
            fileEntity.setYwType("information-news");
            list1 = fileEntityService.queryListByFileEntity(fileEntity);
            newsList.get(i).setFileEntities(list1);
        }
        mv.addObject("bgtList", newsList);
        return mv;
    }

    //按类型列表页分页
    @RequestMapping("/listDoType.html")
    public Object typelistDo(String pagination, String newsType) throws Exception {
        PageParameter pageParameter = JSON.parseObject(pagination.replaceAll("&＃39;", "\""), PageParameter.class);
        PageData pageData = getPageData(informationPublishPressReleaseService.queryPagebm(pageParameter, newsType));
        return pageData;
    }

}

